#ifndef _EVENTLOOPTHREAD_H
#define _EVENTLOOPTHREAD_H

#include "Condition.h"
#include "EventLoop.h"
#include "MutexLock.h"
#include "mutex.h"
#include "thread.h"

namespace droneswarm
{

    //这是执行事件循环的线程类。该事件循环会在一个线程内执行。
    class EventLoopThread
    {
    public:
        EventLoopThread();
        ~EventLoopThread();
        EventLoop *startLoop();

    private:
        void threadFunc();  //线程执行的函数
        EventLoop *loop_;   //实现循环
        bool exiting_;      //是否退出
        Thread thread_;     //线程
        MutexLock mutex_;   //互斥锁
        Condition cond_;    //条件变量
        // pthread_cond_t 是 POSIX 线程库（pthread）中用于条件变量的类型。
    private:
        EventLoopThread( const EventLoopThread & ) = delete;
        EventLoopThread( const EventLoopThread && ) = delete;
        EventLoopThread &operator=( const EventLoopThread & ) = delete;
    };
}  // namespace droneswarm

#endif